package nth.bananas.game;

import java.io.File;
import java.util.Set;


public class Game {
	
	static boolean verbose = true;
	static int roundsPlayed = 0; 

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.setProperty("wordnet.database.dir", "C:\\Program Files\\WordNet\\2.1\\dict\\");
		int playerCount = 7;
		
		if (verbose) {
			System.out.printf("Starting game with %d players%n", playerCount);
		}

		String config = args.length == 0 ? "default.xml" : args[1];
		PieceCounts counts = new PieceCounts(config);
		
		Player[] players = new Player[playerCount];
		GameMaster gm = new GameMaster(playerCount, counts);

		for (int i = 0; i < playerCount; i++) {
			players[i] = new Player(gm);
		}

		if (verbose) {
			System.out.println("Dealing starting pieces.");
		}
		
		for (Player p : players) {
			if (verbose) {
				System.out.printf("\tDealing to player %s%n", p);
			}
			p.takeInitialPieces();
		}

		Set<Player> winners = null;
		while (winners == null) {
			winners = gm.playGame(players);
		}
		
		if (verbose) {
			printWinners(winners);
		}
	}

	private static void printWinners(Set<Player> winners) {
		System.out.println("Winners found:");
		for (Player p : winners) {
			System.out.printf("\t%s", p);
		}
	}
	
	public static boolean isVerbose() {
		return verbose;
	}

}


